package str

import "sort"

func KMP(hashkey string, needel string) int {
	var next []int = make([]int, 0)
	next = append(next, 0)
	j := 0
	for i := 1; i < len(needel); i++ {
		for j > 0 && needel[i] != needel[j] {
			j = next[j-1]
		}
		if needel[i] == needel[j] {
			j++
		}
		next = append(next, j)
	}

	j = 0
	for i := 0; i < len(hashkey); i++ {
		for j > 0 && hashkey[i] != needel[j] {
			j = next[j-1]
		}
		if hashkey[i] == needel[j] {
			j++
		}
		if j == len(needel) {
			return i - len(needel) + 1
		}
	}
	return -1
}

func SortStrs(strs []string) []string {
	sort.Slice(strs, func(i, j int) bool {
		return strs[i] < strs[j]
	})
	return strs
}
